<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>mainwindow.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-tools-completer-example.html">Completer Example</a></td><td >mainwindow.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">mainwindow.cpp 示例文件</h1>
<span class="subtitle">tools/completer/mainwindow.cpp</span>
<!-- $$$tools/completer/mainwindow.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the examples of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>
  <span class="preprocessor">#include &quot;fsmodel.h&quot;</span>
  <span class="preprocessor">#include &quot;mainwindow.h&quot;</span>

  MainWindow<span class="operator">::</span>MainWindow(<span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qmainwindow.html">QMainWindow</a></span>(parent)<span class="operator">,</span> completer(<span class="number">0</span>)<span class="operator">,</span> lineEdit(<span class="number">0</span>)
  {
      createMenu();

      <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>centralWidget <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>;

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>modelLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
      modelLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Model&quot;</span>));

      modelCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      modelCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;QFileSytemModel&quot;</span>));
      modelCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;QFileSytemModel that shows full path&quot;</span>));
      modelCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Country list&quot;</span>));
      modelCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Word list&quot;</span>));
      modelCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>modeLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
      modeLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Completion Mode&quot;</span>));
      modeCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      modeCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Inline&quot;</span>));
      modeCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Filtered Popup&quot;</span>));
      modeCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Unfiltered Popup&quot;</span>));
      modeCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">1</span>);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>caseLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
      caseLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Case Sensitivity&quot;</span>));
      caseCombo <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcombobox.html">QComboBox</a></span>;
      caseCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Case Insensitive&quot;</span>));
      caseCombo<span class="operator">-</span><span class="operator">&gt;</span>addItem(tr(<span class="string">&quot;Case Sensitive&quot;</span>));
      caseCombo<span class="operator">-</span><span class="operator">&gt;</span>setCurrentIndex(<span class="number">0</span>);

      <span class="type"><a href="qlabel.html">QLabel</a></span> <span class="operator">*</span>maxVisibleLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
      maxVisibleLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Max Visible Items&quot;</span>));
      maxVisibleSpinBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qspinbox.html">QSpinBox</a></span>;
      maxVisibleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setRange(<span class="number">3</span><span class="operator">,</span><span class="number">25</span>);
      maxVisibleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">10</span>);

      wrapCheckBox <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcheckbox.html">QCheckBox</a></span>;
      wrapCheckBox<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Wrap around completions&quot;</span>));
      wrapCheckBox<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);

      contentsLabel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>;
      contentsLabel<span class="operator">-</span><span class="operator">&gt;</span>setSizePolicy(<span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed<span class="operator">,</span> <span class="type"><a href="qsizepolicy.html">QSizePolicy</a></span><span class="operator">::</span>Fixed);

      connect(modelCombo<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(changeModel()));
      connect(modeCombo<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(changeMode(<span class="type">int</span>)));
      connect(caseCombo<span class="operator">,</span> SIGNAL(activated(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(changeCase(<span class="type">int</span>)));
      connect(maxVisibleSpinBox<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(changeMaxVisible(<span class="type">int</span>)));

      lineEdit <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlineedit.html">QLineEdit</a></span>;

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>layout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(modelLabel<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(modelCombo<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(modeLabel<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);  layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(modeCombo<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(caseLabel<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);  layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(caseCombo<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(maxVisibleLabel<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">0</span>); layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(maxVisibleSpinBox<span class="operator">,</span> <span class="number">3</span><span class="operator">,</span> <span class="number">1</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(wrapCheckBox<span class="operator">,</span> <span class="number">4</span><span class="operator">,</span> <span class="number">0</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(contentsLabel<span class="operator">,</span> <span class="number">5</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      layout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(lineEdit<span class="operator">,</span> <span class="number">6</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">2</span>);
      centralWidget<span class="operator">-</span><span class="operator">&gt;</span>setLayout(layout);
      setCentralWidget(centralWidget);

      changeModel();

      setWindowTitle(tr(<span class="string">&quot;Completer&quot;</span>));
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>setFocus();
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>createMenu()
  {
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>exitAction <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;Exit&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>aboutAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;About&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);
      <span class="type"><a href="qaction.html">QAction</a></span> <span class="operator">*</span>aboutQtAct <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qaction.html">QAction</a></span>(tr(<span class="string">&quot;About Qt&quot;</span>)<span class="operator">,</span> <span class="keyword">this</span>);

      connect(exitAction<span class="operator">,</span> SIGNAL(triggered())<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> SLOT(quit()));
      connect(aboutAct<span class="operator">,</span> SIGNAL(triggered())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(about()));
      connect(aboutQtAct<span class="operator">,</span> SIGNAL(triggered())<span class="operator">,</span> <a href="qapplication.html#qApp">qApp</a><span class="operator">,</span> SLOT(aboutQt()));

      <span class="type"><a href="qmenu.html">QMenu</a></span><span class="operator">*</span> fileMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;File&quot;</span>));
      fileMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(exitAction);

      <span class="type"><a href="qmenu.html">QMenu</a></span><span class="operator">*</span> helpMenu <span class="operator">=</span> menuBar()<span class="operator">-</span><span class="operator">&gt;</span>addMenu(tr(<span class="string">&quot;About&quot;</span>));
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(aboutAct);
      helpMenu<span class="operator">-</span><span class="operator">&gt;</span>addAction(aboutQtAct);
  }

  <span class="type"><a href="../qtcore/qabstractitemmodel.html">QAbstractItemModel</a></span> <span class="operator">*</span>MainWindow<span class="operator">::</span>modelFromFile(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span><span class="operator">&amp;</span> fileName)
  {
      <span class="type"><a href="../qtcore/qfile.html">QFile</a></span> file(fileName);
      <span class="keyword">if</span> (<span class="operator">!</span>file<span class="operator">.</span>open(<span class="type"><a href="../qtcore/qfile.html">QFile</a></span><span class="operator">::</span>ReadOnly))
          <span class="keyword">return</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstringlistmodel.html">QStringListModel</a></span>(completer);

  <span class="preprocessor">#ifndef QT_NO_CURSOR</span>
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>setOverrideCursor(<span class="type"><a href="../qtgui/qcursor.html">QCursor</a></span>(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>WaitCursor));
  <span class="preprocessor">#endif</span>
      <span class="type"><a href="../qtcore/qstringlist.html">QStringList</a></span> words;

      <span class="keyword">while</span> (<span class="operator">!</span>file<span class="operator">.</span>atEnd()) {
          <span class="type"><a href="../qtcore/qbytearray.html">QByteArray</a></span> line <span class="operator">=</span> file<span class="operator">.</span>readLine();
          <span class="keyword">if</span> (<span class="operator">!</span>line<span class="operator">.</span>isEmpty())
              words <span class="operator">&lt;</span><span class="operator">&lt;</span> line<span class="operator">.</span>trimmed();
      }

  <span class="preprocessor">#ifndef QT_NO_CURSOR</span>
      <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">::</span>restoreOverrideCursor();
  <span class="preprocessor">#endif</span>

      <span class="keyword">if</span> (<span class="operator">!</span>fileName<span class="operator">.</span>contains(QLatin1String(<span class="string">&quot;countries.txt&quot;</span>)))
          <span class="keyword">return</span> <span class="keyword">new</span> <span class="type"><a href="../qtcore/qstringlistmodel.html">QStringListModel</a></span>(words<span class="operator">,</span> completer);

      <span class="comment">// The last two chars of the countries.txt file indicate the country</span>
      <span class="comment">// symbol. We put that in column 2 of a standard item model</span>
      <span class="type"><a href="../qtgui/qstandarditemmodel.html">QStandardItemModel</a></span> <span class="operator">*</span>m <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="../qtgui/qstandarditemmodel.html">QStandardItemModel</a></span>(words<span class="operator">.</span>count()<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> completer);
      <span class="keyword">for</span> (<span class="type">int</span> i <span class="operator">=</span> <span class="number">0</span>; i <span class="operator">&lt;</span> words<span class="operator">.</span>count(); <span class="operator">+</span><span class="operator">+</span>i) {
          <span class="type"><a href="../qtcore/qmodelindex.html">QModelIndex</a></span> countryIdx <span class="operator">=</span> m<span class="operator">-</span><span class="operator">&gt;</span>index(i<span class="operator">,</span> <span class="number">0</span>);
          <span class="type"><a href="../qtcore/qmodelindex.html">QModelIndex</a></span> symbolIdx <span class="operator">=</span> m<span class="operator">-</span><span class="operator">&gt;</span>index(i<span class="operator">,</span> <span class="number">1</span>);
          <span class="type"><a href="../qtcore/qstring.html">QString</a></span> country <span class="operator">=</span> words<span class="operator">[</span>i<span class="operator">]</span><span class="operator">.</span>mid(<span class="number">0</span><span class="operator">,</span> words<span class="operator">[</span>i<span class="operator">]</span><span class="operator">.</span>length() <span class="operator">-</span> <span class="number">2</span>)<span class="operator">.</span>trimmed();
          <span class="type"><a href="../qtcore/qstring.html">QString</a></span> symbol <span class="operator">=</span> words<span class="operator">[</span>i<span class="operator">]</span><span class="operator">.</span>right(<span class="number">2</span>);
          m<span class="operator">-</span><span class="operator">&gt;</span>setData(countryIdx<span class="operator">,</span> country);
          m<span class="operator">-</span><span class="operator">&gt;</span>setData(symbolIdx<span class="operator">,</span> symbol);
      }

      <span class="keyword">return</span> m;
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeMode(<span class="type">int</span> index)
  {
      <span class="type"><a href="qcompleter.html">QCompleter</a></span><span class="operator">::</span>CompletionMode mode;
      <span class="keyword">if</span> (index <span class="operator">=</span><span class="operator">=</span> <span class="number">0</span>)
          mode <span class="operator">=</span> <span class="type"><a href="qcompleter.html">QCompleter</a></span><span class="operator">::</span>InlineCompletion;
      <span class="keyword">else</span> <span class="keyword">if</span> (index <span class="operator">=</span><span class="operator">=</span> <span class="number">1</span>)
          mode <span class="operator">=</span> <span class="type"><a href="qcompleter.html">QCompleter</a></span><span class="operator">::</span>PopupCompletion;
      <span class="keyword">else</span>
          mode <span class="operator">=</span> <span class="type"><a href="qcompleter.html">QCompleter</a></span><span class="operator">::</span>UnfilteredPopupCompletion;

      completer<span class="operator">-</span><span class="operator">&gt;</span>setCompletionMode(mode);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeCase(<span class="type">int</span> cs)
  {
      completer<span class="operator">-</span><span class="operator">&gt;</span>setCaseSensitivity(cs <span class="operator">?</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseSensitive : <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>CaseInsensitive);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeModel()
  {
      <span class="keyword">delete</span> completer;
      completer <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qcompleter.html">QCompleter</a></span>(<span class="keyword">this</span>);
      completer<span class="operator">-</span><span class="operator">&gt;</span>setMaxVisibleItems(maxVisibleSpinBox<span class="operator">-</span><span class="operator">&gt;</span>value());

      <span class="keyword">switch</span> (modelCombo<span class="operator">-</span><span class="operator">&gt;</span>currentIndex()) {
      <span class="keyword">default</span>:
      <span class="keyword">case</span> <span class="number">0</span>:
          { <span class="comment">// Unsorted QFileSystemModel</span>
              <span class="type"><a href="qfilesystemmodel.html">QFileSystemModel</a></span> <span class="operator">*</span>fsModel <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qfilesystemmodel.html">QFileSystemModel</a></span>(completer);
              fsModel<span class="operator">-</span><span class="operator">&gt;</span>setRootPath(<span class="string">&quot;&quot;</span>);
              completer<span class="operator">-</span><span class="operator">&gt;</span>setModel(fsModel);
              contentsLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Enter file path&quot;</span>));
          }
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="number">1</span>:
          {   <span class="comment">// FileSystemModel that shows full paths</span>
              FileSystemModel <span class="operator">*</span>fsModel <span class="operator">=</span> <span class="keyword">new</span> FileSystemModel(completer);
              completer<span class="operator">-</span><span class="operator">&gt;</span>setModel(fsModel);
              fsModel<span class="operator">-</span><span class="operator">&gt;</span>setRootPath(<span class="string">&quot;&quot;</span>);
              contentsLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Enter file path&quot;</span>));
          }
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="number">2</span>:
          { <span class="comment">// Country List</span>
              completer<span class="operator">-</span><span class="operator">&gt;</span>setModel(modelFromFile(<span class="string">&quot;:/resources/countries.txt&quot;</span>));
              <span class="type"><a href="qtreeview.html">QTreeView</a></span> <span class="operator">*</span>treeView <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtreeview.html">QTreeView</a></span>;
              completer<span class="operator">-</span><span class="operator">&gt;</span>setPopup(treeView);
              treeView<span class="operator">-</span><span class="operator">&gt;</span>setRootIsDecorated(<span class="keyword">false</span>);
              treeView<span class="operator">-</span><span class="operator">&gt;</span>header()<span class="operator">-</span><span class="operator">&gt;</span>hide();
              treeView<span class="operator">-</span><span class="operator">&gt;</span>header()<span class="operator">-</span><span class="operator">&gt;</span>setStretchLastSection(<span class="keyword">false</span>);
              treeView<span class="operator">-</span><span class="operator">&gt;</span>header()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">0</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>Stretch);
              treeView<span class="operator">-</span><span class="operator">&gt;</span>header()<span class="operator">-</span><span class="operator">&gt;</span>setSectionResizeMode(<span class="number">1</span><span class="operator">,</span> <span class="type"><a href="qheaderview.html">QHeaderView</a></span><span class="operator">::</span>ResizeToContents);
              contentsLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Enter name of your country&quot;</span>));
          }
          <span class="keyword">break</span>;
      <span class="keyword">case</span> <span class="number">3</span>:
          { <span class="comment">// Word list</span>
              completer<span class="operator">-</span><span class="operator">&gt;</span>setModel(modelFromFile(<span class="string">&quot;:/resources/wordlist.txt&quot;</span>));
              completer<span class="operator">-</span><span class="operator">&gt;</span>setModelSorting(<span class="type"><a href="qcompleter.html">QCompleter</a></span><span class="operator">::</span>CaseInsensitivelySortedModel);
              contentsLabel<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Enter a word&quot;</span>));
          }
          <span class="keyword">break</span>;
      }

      changeMode(modeCombo<span class="operator">-</span><span class="operator">&gt;</span>currentIndex());
      changeCase(caseCombo<span class="operator">-</span><span class="operator">&gt;</span>currentIndex());
      completer<span class="operator">-</span><span class="operator">&gt;</span>setWrapAround(wrapCheckBox<span class="operator">-</span><span class="operator">&gt;</span>isChecked());
      lineEdit<span class="operator">-</span><span class="operator">&gt;</span>setCompleter(completer);
      connect(wrapCheckBox<span class="operator">,</span> SIGNAL(clicked(bool))<span class="operator">,</span> completer<span class="operator">,</span> SLOT(setWrapAround(bool)));
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>changeMaxVisible(<span class="type">int</span> max)
  {
      completer<span class="operator">-</span><span class="operator">&gt;</span>setMaxVisibleItems(max);
  }

  <span class="type">void</span> MainWindow<span class="operator">::</span>about()
  {
      <span class="type"><a href="qmessagebox.html">QMessageBox</a></span><span class="operator">::</span>about(<span class="keyword">this</span><span class="operator">,</span> tr(<span class="string">&quot;About&quot;</span>)<span class="operator">,</span> tr(<span class="string">&quot;This example demonstrates the &quot;</span>
          <span class="string">&quot;different features of the QCompleter class.&quot;</span>));
  }

</pre>
</div>
<!-- @@@tools/completer/mainwindow.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
